Configuring the Build Environment | 您所在的位置:网站首页 › configure build path在哪 › Configuring the Build Environment |
Project properties are specific to your Gradle project. They are defined using blocks in your build script or directly in the project object. For example, the project property myProperty is created in a build file: build.gradle ext { myProperty = findProperty('myProperty') ?: 'Hello, world!' } println "My property value: ${project.ext.myProperty}"You have two options to add project properties, listed in order of priority: Command Line: You can add properties directly to your Project object via the -P command line option. $ ./gradlew build -PmyProperty='Hi, world'System Properties or Environment Variables: You can set project properties with specially-named system properties or environment variables. $ ./gradlew build -Dorg.gradle.project.myProperty='Hi, world'If the environment variable name looks like ORG_GRADLE_PROJECT_prop=somevalue, then Gradle will set a prop property on your project object, with the value of somevalue. Gradle also supports this for system properties, but with a different naming pattern, which looks like org.gradle.project.prop. The following examples will set the foo property on your Project object to "bar". Example 1: Setting a project property via the command line. $ ./gradlew build -Pfoo=barExample 2: Setting a project property via a system property. gradle.properties org.gradle.project.foo=barExample 3: Setting a project property via an environment variable. $ export ORG_GRADLE_PROJECT_foo=barThis feature is very useful when you don’t have admin rights to a continuous integration server and need to set property values that are not easily visible. Since you cannot use the -P option in that scenario nor change the system-level configuration files, the correct strategy is to change the configuration of your continuous integration build job, adding an environment variable setting that matches an expected pattern. This won’t be visible to normal users on the system. You can access a project property in your build script simply by using its name, as you would a variable. |
CopyRight 2018-2019 实验室设备网 版权所有 |